﻿using System;
using Wombat.Core.Services;

namespace Wombat.Core.Extensions
{
    public static class TagStateServiceExtionsions
    {
        public static double? GetLeftDeviation(this ITagStateService tagStateService, Guid tagId,
                                                  DateTime lastPointTime, double? lastValue)
        {
            if (lastValue == null)
                return null;
            var futureValue = default(object);
            if (tagStateService.TryGetTagValueAt(tagId, lastPointTime.AddTicks(1), out futureValue))
            {
                if (futureValue == null)
                    return null;
                return (Double) futureValue - lastValue.Value;
            }
            return null;
        }
    }
}
